home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000099_icon-group-sender _Tue Apr 1 13:38:29 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 1 Apr 1997 16:42:30 MST
  2. Message-Id: <334101C5.6EED@charlie.cns.iit.edu>
  3. Date: Tue, 01 Apr 1997 13:38:29 +0100
  4. From: "Thomas W. Christopher" <tc@charlie.cns.iit.edu>
  5. Reply-To: tc@charlie.cns.iit.edu
  6. Organization: Illinois Institute of Technology
  7. X-Mailer: Mozilla 3.01Gold (WinNT; I)
  8. Mime-Version: 1.0
  9. To: Norman Ramsey <nr@viper.cs.Virginia.EDU>
  10. Cc: icon-group@cs.arizona.edu
  11. Subject: Re: file locking in unix Icon
  12. References: <5hps5g$5kg@viper.cs.Virginia.EDU>
  13. Content-Type: text/plain; charset=us-ascii
  14. Content-Transfer-Encoding: 7bit
  15. Errors-To: icon-group-errors@cs.arizona.edu
  16. Status: RO
  17. Content-Length: 1166
  18.  
  19. Norman Ramsey wrote:
  20. > I need an Icon program to maintain a database of received messages.
  21. > Because these messages come in the mail, multiple copies of the
  22. > program can be running at one time.  I'd like to lock the database.
  23. > The Unix flock() primitive provides a readers/writers locking
  24. > capability, which is just what I need, but I'm not sure how to import
  25. > it into Icon.  (I figure it can be done using the dynamic loading
  26. > capability, which I don't understand.)
  27. > Does anybody out there have C code that will implement Icon functions
  28. > to acquire and release locks on the file descriptors underlying Icon
  29. > files?
  30.  
  31. The usual UNIX trick is to use an empty file to be a lock. If the
  32. file exists, it means the lock is set. If it doesn't exist, it means
  33. unlocked.
  34.  
  35. You execute a UNIX "creat" for the file. If the file exists (and you are
  36. not superuser) the creation will fail.
  37.  
  38. If, however, the file does not exist, the creation will be successful.
  39.  
  40. Close and remove the file to unlock.
  41.  
  42. I'm guessing this will work in Icon with open(lockfilename,"c").
  43.  
  44. -- 
  45. -Thomas W. Christopher  http://www.iit.edu/~tc
  46.                         tc@charlie.cns.iit.edu
  47.  
  48.